home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Xconq 7.1.0 / src / xconq-7.1.0 / kernel / imf2imf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-07  |  4.4 KB  |  245 lines  |  [TEXT/R*ch]

  1. /* Manipulate Xconq image format files.
  2.    Copyright (C) 1995 Stanley T. Shebs.
  3.  
  4. Xconq is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.  See the file COPYING.  */
  8.  
  9. #include "config.h"
  10. #include "misc.h"
  11. #include "lisp.h"
  12. #include "imf.h"
  13. extern int numimages;
  14. extern ImageFamily **images;
  15.  
  16. char *indirname;
  17.  
  18. char *outdirname;
  19.  
  20. char imdirname[BUFSIZE];
  21.  
  22. int showprogress = 0;
  23.  
  24. int explode = 0;
  25.  
  26. char *imflib = "";
  27. char *xconqlib = "";
  28.  
  29. char spbuf[BUFSIZE];
  30.  
  31. static void usage PARAMS ((void));
  32.  
  33. int
  34. main(argc, argv)
  35. int argc;
  36. char *argv[];
  37. {
  38.     int i, rslt;
  39.     char *arg;
  40.     FILE *ifp, *ofp, *fp;
  41.     Obj *form;
  42.     int startlineno = 0, endlineno = 0;
  43.  
  44.     init_lisp();
  45.  
  46.     if (argc == 1) usage();
  47.     for (i = 1; i < argc; ++i) {
  48.     arg = argv[i];
  49.     if (strcmp(arg, "-i") == 0) {
  50.         if (i + 1 < argc) {
  51.         indirname = argv[i + 1];
  52.         /* Blast the arg because we'll be scanning the args again
  53.            and we want to ignore it then. */
  54.         argv[i] = NULL;
  55.         argv[i + 1] = NULL;
  56.         ++i;
  57.         } else {
  58.         init_error("No input directory following -i");
  59.         }
  60.     } else if (strcmp(arg, "-o") == 0) {
  61.         if (i + 1 < argc) {
  62.         outdirname = argv[i + 1];
  63.         /* Blast the arg because we'll be scanning the args again
  64.            and we want to ignore it then. */
  65.         argv[i] = NULL;
  66.         argv[i + 1] = NULL;
  67.         ++i;
  68.         } else {
  69.         init_error("No output directory following -o");
  70.         }
  71.     } else if (strcmp(arg, "-p") == 0) {
  72.         showprogress = 1;
  73.         argv[i] = NULL;
  74.     } else if (strcmp(arg, "--help") == 0) {
  75.         usage();
  76.         argv[i] = NULL;
  77.     } else if (strcmp(arg, "--explode") == 0) {
  78.         explode = 1;
  79.         argv[i] = NULL;
  80.     }
  81.     }
  82.     /* Open and read an image directory file (and associated files)
  83.        if supplied. */
  84.     if (indirname != NULL) {
  85.     ifp = fopen(indirname, "r");
  86.     if (ifp != NULL) {
  87.         load_image_families(ifp, TRUE, NULL);
  88.     } else {
  89.         run_warning("Couldn't open \"%s\", ignoring", indirname);
  90.     }
  91.     }
  92.     /* Now append contents of random imf files. */
  93.     for (i = 1; i < argc; ++i) {
  94.     if (argv[i] != NULL) {
  95.         rslt = load_imf_file(argv[i], NULL);
  96.         if (!rslt)
  97.           run_warning("Couldn't open \"%s\", ignoring", argv[i]);
  98.     }
  99.     }
  100.     sort_all_images();
  101.     if (outdirname) {
  102.     /* Write the image directory file. */
  103.     sprintf(imdirname, "%s%s", outdirname, "imf.dir");
  104.     ofp = fopen(imdirname, "w");
  105.     } else {
  106.     ofp = NULL;
  107.     }
  108.     for (i = 0; i < numimages; ++i) {
  109.     if (showprogress)
  110.       fprintf(stderr, "; %s\n", images[i]->name);
  111.     if (explode && outdirname) {
  112.         sprintf(spbuf, "%s%s", outdirname, images[i]->name);
  113.         fp = fopen(spbuf, "w");
  114.         if (fp != NULL) {
  115.         write_imf(fp, images[i]);
  116.         fclose(fp);
  117.         } else {
  118.         fprintf(stderr, "could not open \"%s\"\n", spbuf);
  119.         }
  120.     } else {
  121.         write_imf(stdout, images[i]);
  122.     }
  123.     }
  124.     if (ofp != NULL) {
  125.     fclose(ofp);
  126.     }
  127.     return 0;
  128. }
  129.  
  130. static void
  131. usage()
  132. {
  133.     fprintf(stderr,
  134.         "usage: imf2imf [ -i indir ] [ -o outdir ] [ -p ] [ files ... ]\n");
  135.     exit(1);
  136. }
  137.  
  138. void
  139. close_displays()
  140. {
  141. }
  142.  
  143. int
  144. write_entire_game_state(fname)
  145. char *fname;
  146. {
  147.     return 0;
  148. }
  149.  
  150. /* Need these so we can link in Lisp reader code. */
  151.  
  152. void
  153. announce_read_progress()
  154. {
  155. }
  156.  
  157. void
  158. low_init_error(str)
  159. char *str;
  160. {
  161.     fprintf(stderr, "Error: %s.\n", str);
  162.     fflush(stderr);
  163. }
  164.  
  165. /* A warning just gets displayed, no other action is taken. */
  166.  
  167. void
  168. low_init_warning(str)
  169. char *str;
  170. {
  171.     fprintf(stdout, "Warning: %s.\n", str);
  172.     fflush(stdout);
  173. }
  174.  
  175. /* A run error is fatal. */
  176.  
  177. void
  178. low_run_error(str)
  179. char *str;
  180. {
  181.     fprintf(stderr, "Error: %s.\n", str);
  182.     fflush(stderr);
  183.     exit(1);
  184. }
  185.  
  186. void
  187. low_run_warning(str)
  188. char *str;
  189. {
  190.     fprintf(stdout, "Warning: %s.\n", str);
  191.     fflush(stdout);
  192. }
  193.  
  194. /* Fake definitions of unneeded routines called by lisp.c. */
  195.  
  196. int
  197. keyword_code(str)
  198. char *str;
  199. {
  200.     run_warning("fake keyword_code being called");
  201.     return 0;
  202. }
  203.  
  204. /* Make the table so keyword lookup works. */
  205.  
  206. struct a_key {
  207.     char *name;
  208. } keywordtable[] = {
  209.  
  210. #undef  DEF_KWD
  211. #define DEF_KWD(NAME,code,value)  { NAME },
  212.  
  213. #include "keyword.def"
  214.  
  215.     { NULL }
  216. };
  217.  
  218. char *
  219. keyword_name(k)
  220. enum keywords k;
  221. {
  222.     return keywordtable[k].name;
  223. }
  224.  
  225. int
  226. keyword_value(k)
  227. enum keywords k;
  228. {
  229.     run_warning("fake keyword_value being called");
  230.     return 0;
  231. }
  232.  
  233. void
  234. init_predefined_symbols()
  235. {
  236. }
  237.  
  238. int
  239. lazy_bind(sym)
  240. Obj *sym;
  241. {
  242.     run_warning("fake lazy_bind being called");
  243.     return FALSE;
  244. }
  245.